<?php
	$action = $_POST['action'];	
	switch($action)
	{
		case 'cmt':
			$_COOKIE['answered'] == 1 && !intval($_POST['uid']) ? die(json_encode(array('res'=>'Err','ifo'=>'游客每天只能发表过言论一次，请明天再来或者登录进行回复。'))):'';
			$content = doStrings($_POST['comment']);
			$cmtid = intval($_POST['cid']);
			$tid = intval($_POST['tid']);
			($cmtid&&$tid)||(!$cmtid&&!$tid)?die('Err'):'';
			if($content)
			{
				$s = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js");preg_match('/{.+}/',$s,$r);  
				$i = json_decode($r[0]);  
				$data = array(
					'tid' =>$tid?$tid:0,
					'cid' =>$cmtid?$cmtid:0, 
					'ip'=>getIP(),
					'address'=>$i->country.$i->province.$i->city.'('.$i->isp.')',
					'uid'=>intval($_POST['uid']),
					'uname'=>$_POST['uname'],
					'face'=>$_POST['uface']!='null'?$_POST['uface']:'/public/img/default.png',
					'content'=>$content,
					'status'=>intval($_POST['uid'])?1:2
				);
			}else{
				die(json_encode(array('res'=>'Err','ifo'=>'请填写留言&评论')));
			}
			//写入数据库
			$html = $cmtid ? '<dd class="aslist">'.$content.'<span>'.date('Y-m-d H:i:s').'<a href="'.($data['uid']?"http://pic.dev/personal?uid=".$data['uid']:"javascript:;").'">'.($data['uname']?$data['uname']:$data['address']).'</a></span></dd>' : '<dl class="ask"><dt><a href="'.($data['uid']?"http://pic.dev/personal?uid=".$data['uid']:"javascript:;").'"><img src="/public/img/default.png"/></a></dt><dd class="say"><p><a href="'.($data['uid']?"http://pic.dev/personal?uid=".$data['uid']:"javascript:;").'"><font size="2">'.($data['uname']?$data['uname']:$data['address']).'</font>:</a>'.strchina($content,72).'</p><div class="time"><span>'.date('Y-m-d H:i:s').'</span><span><a href="javascript:;" onclick="answer(this,1103);">回复</a></span></div></dd></dl>';
			if(!$data['uid'])
			{
				setcookie('answered',1,time()+7200, "/", ".one.dev"); 
			}
			$_->cmt->_insert($data)?die(json_encode(array('res'=>'OK','ifo'=>$html))):die(json_encode(array('res'=>'Err','ifo'=>'提交出现意外。')));
			break;
		case 'temp':
			$list = $_->source->_select('',array('cates'=>4,'DESC'=>'addtime','LIMIT'=>(20*($_POST['page']-1)).',20'));
			die(json_encode($list));
			break;
		default:
			die('Err!');
			break;
	}
?>